package com.rfid.emergencywarehouse.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.DividerItemDecoration;

import com.rfid.base.base.BaseListFragment;
import com.rfid.emergencywarehouse.R;
import com.rfid.emergencywarehouse.adapter.KfAdapter;
import com.rfid.emergencywarehouse.entity.AssetOrderDetail;
import com.rfid.emergencywarehouse.entity.BarcodeInfo;
import com.rfid.emergencywarehouse.entity.WorkAre;
import com.rfid.emergencywarehouse.presenter.GetAssetPresenter;
import com.rfid.emergencywarehouse.presenter.GetAssetWithOrderPresenter;
import com.rfid.emergencywarehouse.reader.MDividerItemDecoration;
import com.rfid.emergencywarehouse.view.IGetAssetView;
import com.rfid.emergencywarehouse.view.IGetAssetWithOrderView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GetAssetWithOrderSecondFragment extends BaseListFragment<KfAdapter, WorkAre, GetAssetWithOrderPresenter> implements IGetAssetWithOrderView {

    @BindView(R.id.order_num)
    TextView order_num;
    @BindView(R.id.ylq)
    TextView ylq;
    @BindView(R.id.dlq)
    TextView dlq;
    @BindView(R.id.date)
    TextView date;
    String mOrderId;
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this,view);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mOrderId = bundle.getString("id");
            mPresenter.getKF(bundle.getString("kf"));
        }
        mRecyclerView.addItemDecoration(new MDividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getOrderDetail(mOrderId);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_get_asset_second;
    }

    @Override
    protected KfAdapter getAdapter() {
        return new KfAdapter(mData);
    }

    @Override
    protected int getRecyclerViewId() {
        return R.id.recyclerView;
    }

    @Override
    public GetAssetWithOrderPresenter getPresenter() {
        return new GetAssetWithOrderPresenter();
    }

    @Override
    public void onWorkAres(List<WorkAre> workAres) {
        setData(workAres);
    }

    @Override
    public void onBarcode(String rfid, String barcode) {
    }

    @Override
    public void onBarcodeQuery(BarcodeInfo info, boolean success) {
    }

    @Override
    public void onClick(WorkAre workAre) {
        Bundle bundle = new Bundle();
        bundle.putString("orderId",mOrderId);
        bundle.putString("FromWorkAreaId",workAre.getFromWorkAreaId());
        bundle.putString("order_no",order_num.getText().toString());
        bundle.putString("dlq",workAre.getBarCodePickedCount() + "/" + workAre.getBarCodeTotalCount());
        bundle.putString("kf",workAre.getFromWorkAreaName());
        NavHostFragment.findNavController(this).navigate(R.id.action_getAssetWithOrderSecondFragment_to_getAssetWithOrderFragment,bundle);
    }

    @Override
    public void onOrderDetail(AssetOrderDetail detail) {
        ylq.setText("已领取：" + detail.getBarCodePickedCount());
        dlq.setText("待领取：" + detail.getBarCodePickingCount());
        date.setText("申请日期：" + detail.getCreateTime());
        order_num.setText("申请单号：" + detail.getOriginOrderNo());
    }
}
